import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.metrics.pairwise import cosine_similarity

# 加载数据
data = pd.read_csv('user_data.csv')

# 数据预处理
# 将出行路线转为数值向量
routes = pd.get_dummies(data['travel_route'])

# 计算用户之间的相似度
user_similarity = cosine_similarity(routes)

# 根据相似度推荐
def recommend(user_id, user_similarity):
    similar_users = user_similarity[user_id].argsort()[-5:][::-1]
    recommendations = data[data['user_id'].isin(similar_users)]
    return recommendations

# 示例测试
user_id = 1
recommendations = recommend(user_id, user_similarity)
print(recommendations)